Time Complexity of Knuth-Morris-Pratt String Matching Algorithm
نویسنده
چکیده
This project centers on the evaluation for the time complexity of Knuth-Morris-Pratt(KMP) string matching algorithm. String matching problem is to locate a pattern string within a larger string. The best performance in terms of asymptotic time complexity is currently linear, given by the KMP algorithm. In this algorithm, firstly a prefix for the pattern string is computed and then based on this prefix, only linear time is needed to find the pattern string in the larger string. In details of both steps, the prefix computation and matcher, two loops are needed, where one goes over the whole string and the other loop travels back to some point of the prefix array. I test these two steps with a large number of random input strings, of which the lengths are different, and for evaluation, ranges of the strings are also under control to simulate the various cases. As much as possible, I expect to get the tight analysis of the KMP algorithm’s time complexity. During these tests, the numbers of basic operations are recorded and then linear analysis is conducted, giving the coefficients of linear regression and the correlation coefficient. Finally, together with the analysis, it is concluded that the linear time complexity is validated based on the experiments.
منابع مشابه
Tight Comparison Bounds for the String Prefix-Matching Problem
In the string preex-matching problem one is interested in nding the longest preex of a pattern string of length m that occurs starting at each position of a text string of length n. This is a natural generalization of the string matching problem where only occurrences of the whole pattern are sought. The Knuth-Morris-Pratt string matching algorithm can be easily adapted to solve the string pree...
متن کاملEfficient validation and construction of Knuth–Morris–Pratt arrays
Knuth-Morris-Pratt (KMP) arrays are known as the ”failure function” of the Knuth-Morris-Pratt string matching algorithm. We present an algorithm to check if an integer array is a KMP array. This gives a method for computing all the distinct KMP arrays.
متن کاملMultithreaded Implementation of Hybrid String Matching Algorithm
Reading and taking reference from many books and articles, and then analyzing the Navies algorithm, Boyer Moore algorithm and Knuth Morris Pratt (KMP) algorithm and a variety of improved algorithms, summarizes various advantages and disadvantages of the pattern matching algorithms. And on this basis, a new algorithm – Multithreaded Hybrid algorithm is introduced. The algorithm refers to Boyer M...
متن کاملL 16 — April 19 , 2012
In this lecture, we consider the string matching problem finding some or all places in a text where the query string occurs as a substring. From the perspective of a one-shot approach, we can solve string matching in O(|T |) time, where |T | is the size of our text. This purely algorithmic approach has been studied extensively in the papers by Knuth-Morris-Pratt [6], Boyer-Moore [1], and Rabin-...
متن کاملFast Searching in Packed Strings
Given strings P and Q the (exact) string matching problem is to find all positions of substrings in Q matching P . The classical Knuth-Morris-Pratt algorithm [SIAM J. Comput., 1977] solves the string matching problem in linear time which is optimal if we can only read one character at the time. However, most strings are stored in a computer in a packed representation with several characters in ...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 2010